<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  
    
      
    

    
  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic|PT Mono:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />








  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=5.1.0" />






<meta name="description" content="java 培训笔记

第三章Scanner重点：Scanner input= new Scanner(System.in) 在整个程序里面，只用写一次就可以了。然后input可以对于任意输出来进行调用。input.close();//清除input里面的值
boolean（布尔）类型boolean类型的值真：true假：false例如：boolean isTiaoJian1=javaScore&amp;">
<meta property="og:type" content="article">
<meta property="og:title" content="java">
<meta property="og:url" content="https://rsl140.github.io/blog/2017/05/09/java/index.html">
<meta property="og:site_name" content="XiaoSi">
<meta property="og:description" content="java 培训笔记

第三章Scanner重点：Scanner input= new Scanner(System.in) 在整个程序里面，只用写一次就可以了。然后input可以对于任意输出来进行调用。input.close();//清除input里面的值
boolean（布尔）类型boolean类型的值真：true假：false例如：boolean isTiaoJian1=javaScore&amp;">
<meta property="og:updated_time" content="2017-09-06T09:23:46.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="java">
<meta name="twitter:description" content="java 培训笔记

第三章Scanner重点：Scanner input= new Scanner(System.in) 在整个程序里面，只用写一次就可以了。然后input可以对于任意输出来进行调用。input.close();//清除input里面的值
boolean（布尔）类型boolean类型的值真：true假：false例如：boolean isTiaoJian1=javaScore&amp;">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://rsl140.github.io/blog/2017/05/09/java/"/>





  <title> java | XiaoSi </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  














  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">XiaoSi</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://rsl140.github.io/blog/blog/2017/05/09/java/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Summer">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/uploads/1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="XiaoSi">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                java
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-05-09T15:48:26+08:00">
                2017-05-09
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/blog/2017/05/09/java/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count" data-disqus-identifier="2017/05/09/java/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o">阅读次数</i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>次
            </span>
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <blockquote>
<p>java 培训笔记</p>
</blockquote>
<h1 id="第三章"><a href="#第三章" class="headerlink" title="第三章"></a>第三章</h1><h2 id="Scanner"><a href="#Scanner" class="headerlink" title="Scanner"></a>Scanner</h2><p>重点：Scanner input= new Scanner(System.in) 在整个程序里面，只用写一次就可以了。然后input可以对于任意输出来进行调用。<br>input.close();//清除input里面的值</p>
<h2 id="boolean（布尔）类型"><a href="#boolean（布尔）类型" class="headerlink" title="boolean（布尔）类型"></a>boolean（布尔）类型</h2><p>boolean类型的值<br>真：true<br>假：false<br>例如：boolean isTiaoJian1=javaScore&gt;98 &amp;&amp; musicScore &gt;80;<br>例如命名：boolean isBig<br>注：需要注意的一点是，boolean在命名的时候开头需要用is</p>
<h2 id="if结构"><a href="#if结构" class="headerlink" title="if结构"></a>if结构</h2><p>多重if执行结构为1次或0次，不会执行更多的次数。所以多重if需要遵循从前往后的执行顺序。</p>
<p>在if里面，如果是字符串char和String进行比较的话，需要使用equals方法<br>例如：if(sex.equals(“男”))<br>当如果需要对常量和变量进行比较的时候，需要把常量写在前面，变量写后面<br>例如：if(“男”.equals(sex))</p>
<h2 id="switch中可以使用的数据类型："><a href="#switch中可以使用的数据类型：" class="headerlink" title="switch中可以使用的数据类型："></a>switch中可以使用的数据类型：</h2><ol>
<li>char、short、int、long、bool 基本类型都可以用于switch语句。 2. float、double都不能用于switch语句。 3. enum类型,即枚举类型可以用于switch语句。4.String可以用于switch语句，但是限定于jdk1.7版本以上</li>
</ol>
<a id="more"></a>
<h2 id="比较switch和多重if选择结构"><a href="#比较switch和多重if选择结构" class="headerlink" title="*比较switch和多重if选择结构"></a>*比较switch和多重if选择结构</h2><p>相同点<br>都是用来处理多分支条件的结构<br>不同点<br>switch选择结b构：只能处理等值条件判断的情况，而且条件必须是整型变量或字符型变量或String。<br>多重if选择结构：没有swithc选择机构的限制，特别适合某个变量处于某个连续区间时的情况。</p>
<h2 id="退出命令"><a href="#退出命令" class="headerlink" title="退出命令"></a>退出命令</h2><p>System.exit(0);  //程序结束执行，0正常退出，1是异常推出</p>
<h2 id="判定输入是否异常"><a href="#判定输入是否异常" class="headerlink" title="判定输入是否异常"></a>判定输入是否异常</h2><p>hasNextInt //异常判断</p>
<p>==比较的是变量的地址<br>equals比较的是String类型变量的值</p>
<h1 id="第四章"><a href="#第四章" class="headerlink" title="第四章"></a>第四章</h1><p>循环的四要素<br>1、初始化循环变量<br>2、判断循环条件<br>3、执行循环操作<br>4、迭代循环变量</p>
<p>while循环和do-while循环的区别<br>*语法不同</p>
<p><em>执行次序不同
</em>初始情况不满足循环条件时<br>1、while循环一次都不会执行<br>2、do-while循环不管任何情况都至少执行一次</p>
<h1 id="第五章"><a href="#第五章" class="headerlink" title="第五章"></a>第五章</h1><h2 id="案例：实现整数反转"><a href="#案例：实现整数反转" class="headerlink" title="案例：实现整数反转"></a>案例：实现整数反转</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">mian</span><span class="params">(String[ ] args)</span></span>&#123;</div><div class="line"><span class="keyword">int</span> val=<span class="number">12345</span>;</div><div class="line"><span class="keyword">int</span> r_digit;</div><div class="line">System.out.print(<span class="string">"反转后的整数是："</span>);</div><div class="line"><span class="keyword">while</span>(val!=<span class="number">0</span>)&#123;</div><div class="line">        r_digit=val%<span class="number">10</span>;</div><div class="line">        System.out.print(r_digit);</div><div class="line">        val=val/<span class="number">10</span>;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="for循环执行条件"><a href="#for循环执行条件" class="headerlink" title="for循环执行条件"></a>for循环执行条件</h2><p>1、参数初始化<br>2、条件判断<br>3、循环操作<br>4、更新循环变量<br>5、条件判断（如果为true）则再次执行循环体</p>
<h2 id="for循环的条件使用方式"><a href="#for循环的条件使用方式" class="headerlink" title="for循环的条件使用方式"></a>for循环的条件使用方式</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/*</span></div><div class="line">*1.初始化循环变量可以不写在for里面</div><div class="line">*2.迭代可以不写在for里面</div><div class="line">*3.判断条件也可以不写在for里面，但要在循环体里面写上break</div><div class="line">*/</div><div class="line">案例展示</div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">mian</span><span class="params">(String[ ] args)</span></span>&#123;</div><div class="line">    <span class="keyword">int</span> sum=<span class="number">0</span>;<span class="comment">//累加</span></div><div class="line">    <span class="keyword">int</span> i=<span class="number">0</span>;</div><div class="line">    <span class="keyword">for</span>()&#123;</div><div class="line">        <span class="keyword">if</span>(i&gt;<span class="number">10</span>)&#123;</div><div class="line">            <span class="keyword">break</span>;<span class="comment">//终止循环</span></div><div class="line">            &#125;</div><div class="line">        sum+=i;</div><div class="line">        i++;</div><div class="line">    &#125;</div><div class="line">    System.out.println(<span class="string">"1到10累加的和为："</span>+sum);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="break和Continue；"><a href="#break和Continue；" class="headerlink" title="break和Continue；"></a>break和Continue；</h2><p>break   终止整个循环<br>continue  终止当前次的循环<br>使用场合<br>break可用于switch结构和循环结构中<br>Continue只能用于循环结构<br>作用（循环结构中）<br>break语句终止某个循环，程序跳转到循环块外的下一条语句。<br>continue跳出本次循环，进入下一次循环<br>？？continue在多重判断里面是否有作用呢？？</p>
<p>ctrl+shift+o是导入包<br>java里面的%的使用 NumberFormat(数字格式化)<br>//百度搜索 java NumberFormat<br>/<em>指定要输出的格式化，”##.00%”这个格式是固定的</em>/<br>DecimalFormat df1=new DecimalFormat(“##.00%”);<br>/<em>格式化</em>/<br>String str=df1.format(0.389);<br>System.out.println(str)</p>
<h2 id="java如何获取当前时间"><a href="#java如何获取当前时间" class="headerlink" title="java如何获取当前时间"></a>java如何获取当前时间</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">Data currentDate=<span class="keyword">new</span> data();</div><div class="line">System.out.println(currentDate);<span class="comment">//标准格里高利历</span></div><div class="line"><span class="comment">/*简易化日期显示，"yyyy/MM/dd hh:mm:ss"这个格式是固定的*/</span></div><div class="line">SimpleDateFormat sdf=<span class="keyword">new</span> SimpleDateFormat(<span class="string">"yyyy/MM/dd hh:mm:ss"</span> );</div><div class="line">注：大写的mm是月，小写的mm是分钟</div><div class="line">String dateStr=sdf.format(currentDate);</div><div class="line">System.out.println(dateStr);</div><div class="line">Date newDate=sdf.parse(dateStr);<span class="comment">//把字符转化成日期</span></div></pre></td></tr></table></figure>
<p>嵌套循环的特点：<br>外层循环循环1次，内层循环要循环所有次。</p>
<h1 id="第六章"><a href="#第六章" class="headerlink" title="第六章"></a>第六章</h1><h2 id="什么是数组："><a href="#什么是数组：" class="headerlink" title="什么是数组："></a>什么是数组：</h2><p>数组是一个变量，存储相同数据类型的一组数据<br>数组和变量的区别<br>变量：声明一个变量就是在内存空间划出一块合适的空间<br>数组：声明一个数组就是在内存空间划出一串连续的空间</p>
<h2 id="数组的结构和基本要素"><a href="#数组的结构和基本要素" class="headerlink" title="数组的结构和基本要素"></a>数组的结构和基本要素</h2><p>标识符：数组的名称，用于区分不同的数组<br>数组元素：实际就是变量名，用来确定数组的起始位置<br>元素下标：数组中每个元素的编号<br>数组元素：数组中存放内容</p>
<p>元素下标标明了元素在数组中的位置，从0开始<br>数组长度固定不变，避免数组越界<br>数组中的所有元素必须是相同的数据类型</p>
<h2 id="使用数组的四步："><a href="#使用数组的四步：" class="headerlink" title="使用数组的四步："></a>使用数组的四步：</h2><p>1、声明数组 int[] a;<br>2、分配空间 a=new int[5];<br>数据类型[ ]  数组名 = new 数据类型[大小]；<br>3、赋值 a[0]=8;<br>4、处理数据 a[0]=a[0]*10;</p>
<h2 id="关于length"><a href="#关于length" class="headerlink" title="关于length"></a>关于length</h2><p>数组的长度使用：数组名.length<br>数组的length：没有括号的叫属性，有括号的叫方法</p>
<p>当基本数据类型被定义到堆空间的时候，java默认分配值（int double boolean）<br>引用数据数据类型不会分配值，是空的（String）<br>int：0<br>double:0.0<br>boolean:false<br>String:null</p>
<h2 id="关于数组错误异常的提示："><a href="#关于数组错误异常的提示：" class="headerlink" title="关于数组错误异常的提示："></a>关于数组错误异常的提示：</h2><p>NullpointerException  空指针异常  检查是否没有没有对引用类型赋值<br>ArrayIndexOutOfboundsException 数组下标越界   检查是否越界，超出长度</p>
<h2 id="for-each（加强循环）"><a href="#for-each（加强循环）" class="headerlink" title="for each（加强循环）"></a>for each（加强循环）</h2><p>for（String pro:products）{<br>System.out.println(pro);<br>}<br>步长 是指访问数组里面的量的时候，所需要的执行顺序。<br>例如：如果我要访问一个数组中每一个数的话，就可以用加强循环<br>   如果我要访问一个组数中不是每一个数的画（或者需要获取下标的时候也不能使用），就不能用加强循环。</p>
<p><code>Arrays.sort</code>(数组);//对数组进行升序排列</p>
<p>基本数据类型：改变一个变量的值，不会去影响另外一个变量的值。</p>
<p><code>compare</code></p>
<h2 id="对象"><a href="#对象" class="headerlink" title="对象"></a>对象</h2><p>用来描述客观事物的一个实体，由一组属性和方法构成。<br>对象的属性和方法<code>通常</code>都是封装在一起的。</p>
<h3 id="类"><a href="#类" class="headerlink" title="类"></a>类</h3><p>具有相同属性和方法的一组对象的集合</p>
<h4 id="定义一个类的步骤"><a href="#定义一个类的步骤" class="headerlink" title="定义一个类的步骤"></a>定义一个类的步骤</h4><p>1.定义类名<br>2.编写类的属性<br>3.编写类的方法</p>
<h4 id="常见错误"><a href="#常见错误" class="headerlink" title="常见错误"></a>常见错误</h4><p>不能在方法外部直接写程序逻辑代码 如:<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">demo</span></span>&#123;</div><div class="line">    <span class="keyword">int</span> age =<span class="number">20</span>;</div><div class="line"></div><div class="line">    <span class="keyword">if</span>(age &lt; <span class="number">20</span>)&#123;</div><div class="line">        System.out.println(<span class="string">"XXXX"</span>); <span class="comment">// 逻辑程序不能写在方法外部 除非加个代码块&#123;&#125;</span></div><div class="line">    &#125;</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">show</span><span class="params">()</span></span>&#123;</div><div class="line">        <span class="keyword">return</span> age;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<h4 id="作用域"><a href="#作用域" class="headerlink" title="作用域"></a>作用域</h4><p>局部变量的作用域仅限于定义他的方法<br>成员变量的作用域在整个类内部都是可见的</p>
<p>java会给成员变量一个初值<br>java不会给局部变量赋予初值<br>在同一个方法中，不允许有同名局部变量；在不同的方法中，可以有同名局部变量<br>两类变量同名时，局部变量具有更高的优先级</p>
<p><code>堆内存</code>：保存对象的真正数据，都是每一个对象的属性内容<br><code>栈内存</code>：保存的时一块堆内存的地址</p>
<h4 id="递归"><a href="#递归" class="headerlink" title="递归"></a>递归</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Hello</span></span>&#123;</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] arry)</span></span>&#123;</div><div class="line">        System.out.println(add(<span class="number">100</span>));</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">add</span><span class="params">(<span class="keyword">int</span> num)</span></span>&#123;</div><div class="line">        <span class="keyword">if</span>(num == <span class="number">1</span>)&#123;<span class="comment">//结束条件</span></div><div class="line">            <span class="keyword">return</span> <span class="number">1</span>;<span class="comment">//不再向后继续加了</span></div><div class="line">        &#125;</div><div class="line">        <span class="keyword">return</span> num+add(num-<span class="number">1</span>);<span class="comment">//修改参数内容</span></div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h1 id="字符串-String"><a href="#字符串-String" class="headerlink" title="字符串(String)"></a>字符串(String)</h1><p><code>concat</code> 字符串链接(数字类型调用不了)<br><code>substring(3)</code>从第3个(包含)开始截取到最后<br><code>substring(2,5)</code>从第2个(包含)开始截取到第5个(不包含)</p>
<h2 id="文件名判断方法"><a href="#文件名判断方法" class="headerlink" title="文件名判断方法"></a>文件名判断方法</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">String fileName = <span class="string">"djkl.java"</span>;</div><div class="line"><span class="keyword">int</span> index = fileName.lastIndexOf(<span class="string">"."</span>);</div><div class="line"><span class="comment">//index != -1 找不到</span></div><div class="line"><span class="keyword">if</span>(index != -<span class="number">1</span> &amp;&amp; index != <span class="number">0</span> &amp;&amp; fileName.substring(index+<span class="number">1</span>).equals(<span class="string">"java"</span>))&#123;</div><div class="line">        System.out.println(<span class="string">"有效文件名！"</span>);</div><div class="line">&#125;<span class="keyword">else</span>&#123;</div><div class="line">        System.out.println(<span class="string">"文件名无效！"</span>);</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="comment">/*检查邮箱格式*/</span></div><div class="line"><span class="keyword">if</span>(email.indexOf(<span class="string">'@'</span>) != -<span class="number">1</span> &amp;&amp; email.indexOf(<span class="string">'.'</span>) &gt; email.indexOf(<span class="string">'@'</span>))&#123;</div><div class="line">    emailCorrect = <span class="keyword">true</span>;</div><div class="line">&#125;<span class="keyword">else</span>&#123;</div><div class="line">    System.out.println(<span class="string">"Email无效！"</span>);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="String-StringBuffer-StringBuilder的区别"><a href="#String-StringBuffer-StringBuilder的区别" class="headerlink" title="String StringBuffer StringBuilder的区别"></a>String StringBuffer StringBuilder的区别</h2><h1 id="第十章"><a href="#第十章" class="headerlink" title="第十章"></a>第十章</h1><h2 id="构造函数"><a href="#构造函数" class="headerlink" title="构造函数"></a>构造函数</h2><p>当没有显式声明有参的构造方法的时候，java会默认生成一无参的构造方法<br>一旦声明了有参的构造函数后，java就不会生成无参的构造函数</p>
<h2 id="static"><a href="#static" class="headerlink" title="static"></a>static</h2><p>可以用来修饰属性、方法和代码块<br>修饰的属性和方法称为类属性（类变量）、类方法<br>不使用static修饰的属性和方法，属于单个对象，通常称为实例属性（实例变量）、实例方法<br>static修饰的变量和方法可以通过类名和对象名访问，而不用static修饰的变量和方法只能通过对象名访问<br>final修饰的变量成为常量，其值固定不变</p>
<p>static定义的方法不能调用static的方法或属性<br>非static定义的方法可以调用static的属性或方法</p>
<h2 id="封装"><a href="#封装" class="headerlink" title="封装"></a>封装</h2><p>将类的某些信息隐藏在类内部，不允许外部程序直接访问，而是通过该类提供的方法来实现对隐藏信息的操作和访问<br><span style="color: red">好处：</span>只能通过规定方法访问数据，方便加入控制语句，方便修改实现</p>
<h2 id="抽象类"><a href="#抽象类" class="headerlink" title="抽象类"></a>抽象类</h2><p>1.抽象类的关键字是abstract<br>2.在一个类如果至少有一个abstract方法，那么这个类必须是抽象类<br>3.抽象类里可以包含普通方法和属性<br>4.抽象类的子类必须实现父类的抽象方法，如果不想实现，那么这个子类必须为抽象类<br>5.abstract方法不能写为私有，必须是可见的<br>6.抽象方法不能有实现</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">    <span class="keyword">public</span> <span class="keyword">abstract</span> <span class="class"><span class="keyword">class</span> <span class="title">PetAbstract</span> <span class="keyword">extends</span> <span class="title">Pet</span> </span>&#123;</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">void</span> <span class="title">print</span><span class="params">()</span></span>;<span class="comment">//不能为private</span></div><div class="line">    </div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">text</span><span class="params">()</span></span>&#123;</div><div class="line">        System.out.print(<span class="string">"这是一个普通方法"</span>);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="多态"><a href="#多态" class="headerlink" title="多态"></a>多态</h2><table>
<thead>
<tr>
<th>/</th>
<th>位置</th>
<th>方法名</th>
<th>参数表</th>
<th>返回值</th>
<th>访问修饰符</th>
</tr>
</thead>
<tbody>
<tr>
<td>方法重写</td>
<td>子类</td>
<td>相同</td>
<td>相同</td>
<td>相同</td>
<td>不能比父类更严格</td>
</tr>
<tr>
<td>方法重载</td>
<td>同类</td>
<td>相同</td>
<td>相同</td>
<td>无关</td>
<td>无关</td>
</tr>
</tbody>
</table>
<p><span style="color: red">多态的必要条件</span><br>1.要有继承<br>2.要有重写<br>3.父类引用指向子类对象</p>
<p>多态的好处<br>1.可替换性<br>2.可扩充性<br>3.接口性<br>4.灵活性<br>5.简化性</p>
<h2 id="IO流"><a href="#IO流" class="headerlink" title="IO流"></a>IO流</h2><p>File file = new File(“/Users/<code>UserName #自己的用户名</code>/Desktop/1.html”);<br><code>File.separator</code> 用于代替”/“<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">File.separator+<span class="string">"Users"</span>+File.separator+<span class="string">"UserName"</span>+File.separator+<span class="string">"Desktop"</span>+File.separator+<span class="string">"desktop"</span>+File.separator+<span class="string">"1.html"</span></div></pre></td></tr></table></figure></p>
<h2 id="多线程"><a href="#多线程" class="headerlink" title="多线程"></a>多线程</h2><p>进程：是程序的一次动态执行过程，它对应了从代码加载、执行至执行完毕的一个完整过程。<br>特点：<br>1.进程是系统运行程序的基本单位<br>2.每一个进程有自己的独立的内存空间、一组系统资源。<br>3.每一个进程的内部数据和状态都是完全独立。</p>
<p>线程：进程内部的一个执行单位，它使程序中一个单一的顺序控制流程。</p>
<ul>
<li>引入进程是为了多个程序并发执行，提高资源的利用率和系统吞吐量</li>
<li>引入线程是为了减少程序在并发执行时付出的时空开销</li>
<li>进程间不能共享内存，但线程之间共享内存非常容易</li>
<li>使用多线程实现多任务并发比多进程的效率高</li>
</ul>
<h3 id="实现方法"><a href="#实现方法" class="headerlink" title="实现方法"></a>实现方法</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">方法一:继承Java.lang.Thread类,并覆盖run()方法</div><div class="line">    <span class="class"><span class="keyword">class</span> <span class="title">MyThread</span> <span class="keyword">extends</span> <span class="title">Thread</span> </span>&#123;</div><div class="line">     <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">( )</span> </span>&#123;</div><div class="line">         <span class="comment">/* 覆盖该方法*/</span></div><div class="line">      &#125;</div><div class="line">    &#125;</div><div class="line">方法二:实现Java.lang.Runnable接口,并实现run()方法</div><div class="line">    <span class="class"><span class="keyword">class</span> <span class="title">MyThread</span> <span class="keyword">implements</span> <span class="title">Runnable</span></span>&#123;</div><div class="line">      <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">( )</span> </span>&#123;</div><div class="line">            <span class="comment">/* 实现该方法*/</span> </div><div class="line">      &#125;</div><div class="line">    &#125;</div></pre></td></tr></table></figure>
<h1 id="Tomcat"><a href="#Tomcat" class="headerlink" title="Tomcat"></a>Tomcat</h1><p><code>$ /Library/Tomcat/bin/startup.sh</code>开启服务器<br><code>$ /Library/Tomcat/bin/shutdown.sh</code>关闭服务器<br><code>localhost:8080</code>服务器开启地址<br>webapps 网站放置地址<br><code>localhost:8080/javaJar</code></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2017/04/13/url/" rel="next" title="实用网站收藏">
                <i class="fa fa-chevron-left"></i> 实用网站收藏
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2017/05/09/PATH/" rel="prev" title="mac for command not found">
                mac for command not found <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/blog/uploads/1.jpg"
               alt="Summer" />
          <p class="site-author-name" itemprop="name">Summer</p>
           
              <p class="site-description motion-element" itemprop="description">小思</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/blog/archives/">
                <span class="site-state-item-count">27</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/blog/categories/index.html">
                <span class="site-state-item-count">8</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/blog/tags/index.html">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="http://github.com/rsl140" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://segmentfault.com/u/xiaosi_58ec6bdf9eaab" target="_blank" title="Segmentfault">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  Segmentfault
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#第三章"><span class="nav-number">1.</span> <span class="nav-text">第三章</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Scanner"><span class="nav-number">1.1.</span> <span class="nav-text">Scanner</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#boolean（布尔）类型"><span class="nav-number">1.2.</span> <span class="nav-text">boolean（布尔）类型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#if结构"><span class="nav-number">1.3.</span> <span class="nav-text">if结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#switch中可以使用的数据类型："><span class="nav-number">1.4.</span> <span class="nav-text">switch中可以使用的数据类型：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#比较switch和多重if选择结构"><span class="nav-number">1.5.</span> <span class="nav-text">*比较switch和多重if选择结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#退出命令"><span class="nav-number">1.6.</span> <span class="nav-text">退出命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#判定输入是否异常"><span class="nav-number">1.7.</span> <span class="nav-text">判定输入是否异常</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#第四章"><span class="nav-number">2.</span> <span class="nav-text">第四章</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#第五章"><span class="nav-number">3.</span> <span class="nav-text">第五章</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#案例：实现整数反转"><span class="nav-number">3.1.</span> <span class="nav-text">案例：实现整数反转</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#for循环执行条件"><span class="nav-number">3.2.</span> <span class="nav-text">for循环执行条件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#for循环的条件使用方式"><span class="nav-number">3.3.</span> <span class="nav-text">for循环的条件使用方式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#break和Continue；"><span class="nav-number">3.4.</span> <span class="nav-text">break和Continue；</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#java如何获取当前时间"><span class="nav-number">3.5.</span> <span class="nav-text">java如何获取当前时间</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#第六章"><span class="nav-number">4.</span> <span class="nav-text">第六章</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#什么是数组："><span class="nav-number">4.1.</span> <span class="nav-text">什么是数组：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#数组的结构和基本要素"><span class="nav-number">4.2.</span> <span class="nav-text">数组的结构和基本要素</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用数组的四步："><span class="nav-number">4.3.</span> <span class="nav-text">使用数组的四步：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#关于length"><span class="nav-number">4.4.</span> <span class="nav-text">关于length</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#关于数组错误异常的提示："><span class="nav-number">4.5.</span> <span class="nav-text">关于数组错误异常的提示：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#for-each（加强循环）"><span class="nav-number">4.6.</span> <span class="nav-text">for each（加强循环）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#对象"><span class="nav-number">4.7.</span> <span class="nav-text">对象</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#类"><span class="nav-number">4.7.1.</span> <span class="nav-text">类</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#定义一个类的步骤"><span class="nav-number">4.7.1.1.</span> <span class="nav-text">定义一个类的步骤</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#常见错误"><span class="nav-number">4.7.1.2.</span> <span class="nav-text">常见错误</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#作用域"><span class="nav-number">4.7.1.3.</span> <span class="nav-text">作用域</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#递归"><span class="nav-number">4.7.1.4.</span> <span class="nav-text">递归</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#字符串-String"><span class="nav-number">5.</span> <span class="nav-text">字符串(String)</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#文件名判断方法"><span class="nav-number">5.1.</span> <span class="nav-text">文件名判断方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#String-StringBuffer-StringBuilder的区别"><span class="nav-number">5.2.</span> <span class="nav-text">String StringBuffer StringBuilder的区别</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#第十章"><span class="nav-number">6.</span> <span class="nav-text">第十章</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#构造函数"><span class="nav-number">6.1.</span> <span class="nav-text">构造函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#static"><span class="nav-number">6.2.</span> <span class="nav-text">static</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#封装"><span class="nav-number">6.3.</span> <span class="nav-text">封装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#抽象类"><span class="nav-number">6.4.</span> <span class="nav-text">抽象类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#多态"><span class="nav-number">6.5.</span> <span class="nav-text">多态</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#IO流"><span class="nav-number">6.6.</span> <span class="nav-text">IO流</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#多线程"><span class="nav-number">6.7.</span> <span class="nav-text">多线程</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#实现方法"><span class="nav-number">6.7.1.</span> <span class="nav-text">实现方法</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Tomcat"><span class="nav-number">7.</span> <span class="nav-text">Tomcat</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Summer</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user">本站访客数</i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye">本站总访问量</i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>


        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  



  
  <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/blog/lib/canvas-nest/canvas-nest.min.js"></script>


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.0"></script>



  



  

    <script type="text/javascript">
      var disqus_shortname = 'xiaosi';
      var disqus_identifier = '2017/05/09/java/';

      var disqus_title = "java";


      function run_disqus_script(disqus_script) {
        var dsq = document.createElement('script');
        dsq.type = 'text/javascript';
        dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/' + disqus_script;
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
      }

      run_disqus_script('count.js');

      
        var disqus_config = function () {
            this.page.url = disqus_url;
            this.page.identifier = disqus_identifier;
            this.page.title = disqus_title;
        };
        run_disqus_script('embed.js');
      

    </script>
  













  





  

  

  

  

</body>
</html>
